package com.example.experiment4;


import com.example.experiment4.dao.PersonDao;
import com.example.experiment4.domain.Person;
import com.example.experiment4.service.PersonService;
import com.example.experiment4.service.ReadImgGetData;
import com.example.experiment4.utils.JudgmentInformation;
import com.example.experiment4.utils.ReadImgToOCR;
import com.tencentcloudapi.ocr.v20181119.models.TextDetection;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class test {

    @Resource
    JudgmentInformation information;

    @Resource
    ReadImgToOCR ocr;

    @Resource
    PersonService personService;

    @Resource
    ReadImgGetData data;

    @Resource
    PersonDao dao;

    @Test
    void test1() {
        List<Person> personList = new ArrayList<>();
        Person person = new Person();
        TextDetection[] textDetections = ocr.toOCR("D:\\实验报告\\软件测试\\文件整理新\\文件整理\\jpg图片\\01.jpg");
        System.out.println(textDetections[textDetections.length - 1].getDetectedText());
        for (int i = 0; i < textDetections.length; i++) {
            String res = textDetections[i].getDetectedText();
//            System.out.println(res);
            if (res.contains(";")) {
                res = res.replaceAll(";", "");
//                System.out.println(res);
            }
//            System.out.println(res);


            if (information.isAddress(res)) {
                if (person.getAddress() != null) {

                    personList.add(person);
                    person = new Person();
                    person.setAddress(res);
                    continue;
                }
                person.setAddress(res);
                continue;
            }

            if (information.isName(res)) {
                if (person.getName() != null) {

                    personList.add(person);
                    person = new Person();
                    person.setName(res);
                    continue;
                }
                person.setName(res);

                continue;
            }

            if (information.isPhone(res)) {
                if (person.getPhone() != null) {

                    personList.add(person);
                    person = new Person();
                    person.setPhone(res);
                    continue;
                }
                person.setPhone(res);
                continue;
            }

        }
        for (int i = 0; i < personList.size(); i++) {
            System.out.println(personList.get(i).toString());
        }
//        System.out.println();
    }

    @Test
    void test2() {
//        System.out.println(information.isAddress("11-12"));
//        System.out.println(information.isAddress("11-12-408"));
//        System.out.println(information.isAddress("123456"));
//        System.out.println(information.isName("何家勇何燕妮"));
        System.out.println(information.isPhone("13577318936"));
    }

    @Test
    void test3() {
//        List<Person> personList = data.personList("D:\\\\实验报告\\\\软件测试\\\\文件整理新\\\\文件整理\\\\jpg图片\\\\01.jpg\"");

        for (Integer i = 1; i < 37; i++) {
            String path = "D:\\\\实验报告\\\\软件测试\\\\文件整理新\\\\文件整理\\\\jpg图片\\\\" + i.toString() + ".jpg";
            List<Person> x = data.personList(path);
//            for (Integer j = 0; j < x.size(); j++) {
//                System.out.println(x.get(j).toString());
//            }
            personService.saveData(x);
            x.clear();
        }

//        List<Person> personList = data.personList("D:\\\\\\\\实验报告\\\\\\\\软件测试\\\\\\\\文件整理新\\\\\\\\文件整理\\\\\\\\jpg图片\\\\\\\\\" + i.toString() + \".jpg");
    }

    @Test
    void test4(){
        System.out.println(dao.countPersonByName());
        System.out.println(dao.countPersonByPhone());
        System.out.println(dao.countPersonByPhoneAndAddress());
    }


}
